<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');
require_once './_inc/funct.rigeneraCodice.php';

$aCamForm = array();
require("_inc/const.campiSetdati.php");

$idSetDati = reqVarInt('sd');
$sql_sel = "SELECT *" .
		" FROM rgl_set_dati  " .
		" WHERE id_set_dati = ".$idSetDati;
$objDB->query($sql_sel,'selRec');
if (!$acSD = $objDB->fetch('selRec')) {
	backOnErr('manca sd '.reqvar('sd'));
}
$_REQUEST = array_merge($acSD,$_REQUEST);
if (reqVar('azione') == 'gencod') {
	$msgPag .= rigeneraCodice(reqVarInt('sd'));
} 
if (reqVar('azione') == 'elimina') {
	$msgPag .= eliminaSetDati();
} 

$cmdL = "";
$cmdL .= "<a class=\"cmd1\" href=\"setDatiExport.php?sd=$idSetDati&$sXSNQS\" target='_blank'>export</a>";
$cmdL .= "&nbsp;&nbsp;&nbsp;&nbsp;";
$cmdL .= "<a class=\"cmd1\" href=\"setDatiImport.php?sd=$idSetDati&$sXSNQS\">import</a>";
$cmdL .= "&nbsp;&nbsp;&nbsp;&nbsp;";
$cmdL .= "<a class=\"cmd1\" href=\"setDatiVis.php?azione=gencod&sd=$idSetDati&$sXSNQS\">rigenera codice</a>";
$cmdL .= "&nbsp;&nbsp;&nbsp;&nbsp;";
$cmdL .= "<a class=\"cmd1\" href=\"tdatiIns.php?sd=$idSetDati&$sXSNQS\">nuova tabella</a>";

$cmdR = "&nbsp;&nbsp;&nbsp;&nbsp;";
if (true) {
	$cmdR .= "<a class=\"cmd1\" href=\"javascript:confDel();\">elimina</a>";
	$cmdR .= "&nbsp;&nbsp;&nbsp;&nbsp;";
	$cmdR .= "<a class=\"cmd1\" href=\"setDatiMod.php?sd=$idSetDati&$sXSNQS\">modifica</a>";
}
$cmdR .= cmdTorna(); 
testaHtml('Gestione modelli', $msgPag, 'modl');
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('sd');
?>
<script type="text/javascript">
function confDel() {
	if (confirm("Confermi ?")) {
		document.location.href = "<?="setDatiVis.php?sd=$idSetDati&azione=elimina&$sXSNQS"?>";
	}
}
</script>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Set dati bilancio</td>
   </tr>
<?
echo getHtmlCampiForm($aCamForm,'vis');
?>
   <tr>
      <td class="lab1" colspan='4' align='left'>Dati</td>
      <td class="txt1" colspan='16' align='left'>
      	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='tabDatiVis.php?ttd=1&sd=<?=reqVarInt('sd').'&xsn='.XSN?>' class='cmd1'>Bilancio UE</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='tabDatiVis.php?ttd=2&sd=<?=reqVarInt('sd').'&xsn='.XSN?>' class='cmd1'>Bilancio riclassificato</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='tabDatiVis.php?ttd=3&sd=<?=reqVarInt('sd').'&xsn='.XSN?>' class='cmd1'>Rendiconto finanziario</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='tabDatiVis.php?ttd=11&sd=<?=reqVarInt('sd').'&xsn='.XSN?>' class='cmd1'><?=reqVar('indici1')?></a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='tabDatiVis.php?ttd=12&sd=<?=reqVarInt('sd').'&xsn='.XSN?>' class='cmd1'><?=reqVar('indici2')?></a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      	<a href='tabDatiVis.php?ttd=13&sd=<?=reqVarInt('sd').'&xsn='.XSN?>' class='cmd1'><?=reqVar('indici3')?></a>
		</td>
   </tr>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();

function eliminaSetDati() {
	global $objDB;
	global $sDBG;
	$msg = '';
	$sSql = "SELECT * FROM rgl_mod_rbil WHERE id_set_dati = ".reqVarInt('sd');
	$objDB->query($sSql);
	if ($aX=$objDB->fetch()) {
		$msg .= "set dati referenziato - eliminazione non eseguita<br>";
	}
	if ($msg != '') {
		return $msg;
	}
	$sSql = "DELETE FROM rgl_def_dato WHERE id_set_dati = ".reqVarInt('sd');
	$objDB->exec($sSql);
	$sSql = "DELETE FROM rgl_def_dato_ref WHERE id_set_dati = ".reqVarInt('sd');
	$objDB->exec($sSql);
	$sSql = "DELETE FROM rgl_set_dati WHERE id_set_dati = ".reqVarInt('sd');
	$objDB->exec($sSql);
	backPage('set eliminato');
	exit();
}
